package com.xxx.video.commen.views.recyclerviews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.xxx.video.R;
import com.xxx.video.commen.utils.StringUtils;


public class LoadMoreFootView extends LinearLayout {
    /**
     * tip text view
     */
    private TextView mTvLoadMoreFootViewTip;
    /**
     * load progress bar
     */
    private ProgressBar mPbLoadMoreFootView;
    /**
     * load finish
     */
    public static final int STATE_LOAD_COMPLETE = 201;
    /**
     * loading
     */
    public static final int STATE_LOAD_ING = 202;
    /**
     * no more data
     */
    public static final int STATE_LOAD_NO_MORE_DATA = 203;

    public LoadMoreFootView(Context context) {
        super(context);
        /*
         * init
         */
        init(context);
    }

    public LoadMoreFootView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        /*
         * init
         */
        init(context);
    }

    public LoadMoreFootView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        /*
         * init
         */
        init(context);
    }

    /**
     * init
     *
     * @param context context
     */
    private void init(Context context) {
        View.inflate(context, R.layout.load_more_foot_view, this);
        //width and height
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        //set margin
        lp.setMargins(0, 0, 0, 0);
        //set layout params
        this.setLayoutParams(lp);
        /*
         * init view
         */
        initView();
        /*
         * default not show
         */
        this.setVisibility(GONE);
    }

    /**
     * init view
     */
    private void initView() {
        mTvLoadMoreFootViewTip = findViewById(R.id.tv_load_more_foot_view_tip);
        mPbLoadMoreFootView = findViewById(R.id.pb_load_more_foot_view);
    }

    /**
     * set status
     *
     * @param state status
     */
    public void setState(int state) {
        switch (state) {
            case STATE_LOAD_COMPLETE:
                mPbLoadMoreFootView.setVisibility(VISIBLE);
                this.setVisibility(GONE);
                break;
            case STATE_LOAD_ING:
                mPbLoadMoreFootView.setVisibility(VISIBLE);
                this.setVisibility(VISIBLE);
                mTvLoadMoreFootViewTip.setText(StringUtils.getInstance().getString(R.string.tip_refresh_recycler_view_foot_load_more_ing));
                break;
            case STATE_LOAD_NO_MORE_DATA:
                mPbLoadMoreFootView.setVisibility(GONE);
                this.setVisibility(VISIBLE);
                mTvLoadMoreFootViewTip.setText(StringUtils.getInstance().getString(R.string.tip_refresh_recycler_view_foot_load_more_no_more_data));
                break;
            default:
                break;
        }
    }
}
